Running
With gdb
Other ways to navigate a program are:
For each of these methods, work through the program after setting a breakpoint in main. Take specific care to see what step and stepi see after entering puts. Most of the time, because those are part of standard libraries, we don't need to step into anything.
Let's say we wanted to break on the call to puts
. We can do this by setting a breakpoint for that instruction.
Like this:
gef➤ b *main+25 Breakpoint 1 at 0x8048414
Or like this:
gef➤ b *0x08048414 Note: breakpoint 1 also set at pc 0x08048414 Breakpoint 2 at 0x08048414
When we run the binary and it tries to execute that instruction, the process will pause and drop us into the debugger console
In the debugger console is where we can actually use the debugger to provide various types of analysis, and change things about the binary. For now let's keep looking at breakpoints. To show all breakpoints:
gef➤ info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x08048414 <main+25> breakpoint already hit 1 time 2 breakpoint keep y 0x08048414 <main+25>
or to be short, "info b" or "i b".
To delete a breakpoint Num 2
:
gef➤ delete 2
or to be short "del 2" or "d 2".
We can also set breakpoints for functions like puts
: b *puts
Now let's say we wanted to change the value stored at the memory address 0x08048451
to 0xfacade
:
gef➤ x/g 0x08048451 0x8048451 <__libc_csu_init+33>: 0xff08838d gef➤ set *0x08048451 = 0xfacade gef➤ x/g 0x08048451 0x8048451 <__libc_csu_init+33>: 0xfacade
Let's say we wanted to jump directly to an instruction like 0x08048451
, and skip all instructions in between:
gef➤ j *0x08048451 Continuing at 0x0x08048451.
That was a lot, keep referring to this, your notes, and GDB cheatsheets as you go along.